第十四节 Pyecharts可视化(二)
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true,
        processEnvironments: true
    },
    // Center justify equations in code and markdown cells. Elsewhere
    // we use CSS to left justify single line equations in code cells.
    displayAlign: 'center',
    "HTML-CSS": {
        styles: {'.MathJax_Display': {"margin": 0}},
        linebreaks: { automatic: true }
    }
});
</script>
<!-- End of mathjax configuration --></head>

柱形图

In [1]:
from pyecharts import options as opts
from pyecharts.charts import Bar

bar1 = (
# 图表类型
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
.add_yaxis("商家B", [20, 30, 41, 15, 45, 100])
# 配置项内容
.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
)
bar1.render_notebook()

Out[1]:
    <div id="8db6ed600282481bb2ee64548631aa10" style="width:900px; height:500px;"></div>

横向柱形图

In [2]:
from pyecharts import options as opts
from pyecharts.charts import Bar

def bar_reversal_axis(): # 返回的Bar的类实例
bar1 = (
# 图表类型
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
.add_yaxis("商家B", [20, 30, 41, 15, 45, 100])
# 翻转
.reversal_axis()
# 系列配置项
.set_series_opts(label_opts=opts.LabelOpts(position='right'))
# 配置项内容
.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
)
return bar1

In [3]:
barh = bar_reversal_axis()
barh.render_notebook()
Out[3]:
    <div id="25f87cf2c3d54017a94bfacbcc05be35" style="width:900px; height:500px;"></div>

数据格式要求 不支持直接使用Series,必须 加上tolist()

折线图

In [4]:
from pyecharts import options as opts
from pyecharts.charts import Line

x = ['2018-{:0>2d}'.format(s) for s in range(1,13)]
y1 = [5,10,26,30,35,30,20,26,40,46,40,50]
y2 = [8,20,24,36,40,36,40,45,50,53,48,58]

bar1 = (
# 图表类型
Line()
.add_xaxis(x)
.add_yaxis("基金A", y1)
.add_yaxis("基金B", y2)
# 配置项内容
.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
)
bar1.render_notebook()

Out[4]:
    <div id="08d1d5117da0405fa85b59fe91441440" style="width:900px; height:500px;"></div>

散点图

In [5]:
from pyecharts.charts import Scatter
import numpy as np
import pandas as pd

df = pd.DataFrame()
df['weight'] = np.array([56,67,65,70,57,60,80,85,76,64],dtype='int32')
df['height'] = np.array([162,170,168,172,168,172,180,176,178,170],dtype='int32')
df['height_m'] = [150,160,164,170,160,158,169,173,171,179]

scatter = Scatter()
scatter.add_xaxis(df['weight'])
scatter.add_yaxis('男生',df['height'])
scatter.add_yaxis('女生',df['height_m'])
scatter.set_global_opts(title_opts=opts.TitleOpts(title="Scatter-基本示例"))
scatter.render_notebook()

Out[5]:
    <div id="22f8bc823a1044da8459fd9eb7d654c4" style="width:900px; height:500px;"></div>

散点图数据支撑series类型

箱线图

In [6]:
from pyecharts import options as opts
from pyecharts.charts import Boxplot

v1 = [
[850, 740, 900, 1070, 930, 850, 950, 980, 980, 880]
+ [1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960],
[960, 940, 960, 940, 880, 800, 850, 880, 900]
+ [840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800],
]

v2 = [
[890, 810, 810, 820, 800, 770, 760, 740, 750, 760]
+ [910, 920, 890, 860, 880, 720, 840, 850, 850, 780],
[890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870]
+ [870, 810, 740, 810, 940, 950, 800, 810, 870],
]

c = Boxplot()
c.add_xaxis(["expr1", "expr2"])
c.add_yaxis("A", c.prepare_data(v1))
c.add_yaxis(
"B", c.prepare_data(v2) # 计算 中位数 最小值 最大值…
)
c.set_global_opts(title_opts=opts.TitleOpts(title="BoxPlot-基本示例"))
c.render_notebook()

Out[6]:
    <div id="ad4526dd40d14bf7b7bfb9ce25837326" style="width:900px; height:500px;"></div>

饼图

In [7]:
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker

c = (
Pie()
.add("", [list(z) for z in zip(Faker.choose(), Faker.values())],radius=["30%", "70%"],)
.set_global_opts(title_opts=opts.TitleOpts(title="Pie-基本示例"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%"))

)
c.render_notebook()

Out[7]:
    <div id="2411aa9d9cbf45a9ac4ff29bcb52add1" style="width:900px; height:500px;"></div>

词云图

  • jieba中文分词
  • WordCloud词云库
In [8]:
from pyecharts.charts import WordCloud

words = ['python','jupyter','numpy','pandas','matplotlib','sklearn',
'xgboost','lightGBM','simpy','keras','tensorflow',
'hive','hadoop','spark']
counts = [100,90,65,95,50,60,70,70,20,70,80,80,60,60]

cloud = WordCloud()
cloud.add("文章",zip(words,counts))
cloud.render_notebook()

Out[8]:
    <div id="224f0258f4644de99fbdb9b8fee3724e" style="width:900px; height:500px;"></div>

jieba库

In [9]:
import jieba
In [10]:
text = '据公告,该公司拟公开发行A股数量不超过12,093,342,392股(即不超过本次A股发行后公司已发行总股本的13%,超额配售选择权行使前)。公司可授权主承销商在符合法律法规及监管要求的前提下行使超额配售选择权,超额发售不超过本次发行A股股数(超额配售选择权行使前)15%的A股股份。所募资金将用于5G产业互联网建设项目、云网融合新型信息基础设施项目及科技创新研发项目。中国电信同日还发布了2020年中国电信发布2020年全年财报,公司2020年营运收入3935.6亿元人民币,净利润208.5亿元人民币,市场预估213.2亿元人民币;2020年每股盈利0.26元,市场预期0.27元,去年同期0.25元;5G套餐用户达到8650万户,渗透率24.6%。移动用户达到3.51亿户,净增1545万户,用户市场份额提升至22.0%。'
text_list = jieba.lcut(text)
arr = np.array(text_list)
arr
Building prefix dict from the default dictionary ...
Dumping model to file cache C:\Users\ALGOMA~1\AppData\Local\Temp\jieba.cache
Loading model cost 1.615 seconds.
Prefix dict has been built successfully.
Out[10]:
array(['据', '公告', ',', '该', '公司', '拟', '公开', '发行', 'A股', '数量', '不', '超过',
       '12', ',', '093', ',', '342', ',', '392', '股', '(', '即', '不', '超过',
       '本次', 'A股', '发行', '后', '公司', '已', '发行', '总', '股本', '的', '13%', ',',
       '超额', '配售', '选择权', '行使', '前', ')', '。', '公司', '可', '授权', '主',
       '承销商', '在', '符合', '法律法规', '及', '监管', '要求', '的', '前提', '下', '行使',
       '超额', '配售', '选择权', ',', '超额', '发售', '不', '超过', '本次', '发行', 'A股',
       '股数', '(', '超额', '配售', '选择权', '行使', '前', ')', '15%', '的', 'A股',
       '股份', '。', '所募', '资金', '将', '用于', '5G', '产业', '互联网', '建设项目', '、',
       '云网', '融合', '新型', '信息', '基础设施', '项目', '及', '科技', '创新', '研发', '项目',
       '。', '中国电信', '同日', '还', '发布', '了', '2020', '年', '中国电信', '发布',
       '2020', '年', '全年', '财报', ',', '公司', '2020', '年', '营运', '收入',
       '3935.6', '亿元', '人民币', ',', '净利润', '208.5', '亿元', '人民币', ',', '市场',
       '预估', '213.2', '亿元', '人民币', ';', '2020', '年', '每股', '盈利', '0.26',
       '元', ',', '市场', '预期', '0.27', '元', ',', '去年同期', '0.25', '元', ';',
       '5G', '套餐', '用户', '达到', '8650', '万户', ',', '渗透率', '24.6%', '。',
       '移动用户', '达到', '3.51', '亿户', ',', '净增', '1545', '万户', ',', '用户',
       '市场份额', '提升', '至', '22.0%', '。'], dtype='<U6')
In [11]:
np.unique(arr,return_counts=True)
Out[11]:
(array([',', '0.25', '0.26', '0.27', '093', '12', '13%', '15%', '1545',
        '2020', '208.5', '213.2', '22.0%', '24.6%', '3.51', '342', '392',
        '3935.6', '5G', '8650', 'A股', '、', '。', '万户', '下', '不', '中国电信',
        '主', '了', '云网', '互联网', '产业', '人民币', '亿元', '亿户', '信息', '元', '全年',
        '公司', '公告', '公开', '净利润', '净增', '创新', '前', '前提', '即', '去年同期', '及',
        '发售', '发布', '发行', '可', '同日', '后', '在', '基础设施', '套餐', '将', '已',
        '市场', '市场份额', '年', '建设项目', '总', '所募', '承销商', '拟', '据', '授权', '提升',
        '收入', '数量', '新型', '本次', '每股', '法律法规', '渗透率', '用于', '用户', '的', '盈利',
        '监管', '研发', '科技', '移动用户', '符合', '股', '股份', '股数', '股本', '至', '营运',
        '融合', '行使', '要求', '该', '财报', '资金', '超过', '超额', '达到', '还', '选择权',
        '配售', '项目', '预估', '预期', '(', ')', ',', ';'], dtype='<U6'),
 array([ 3,  1,  1,  1,  1,  1,  1,  1,  1,  4,  1,  1,  1,  1,  1,  1,  1,
         1,  2,  1,  4,  1,  5,  2,  1,  3,  2,  1,  1,  1,  1,  1,  3,  3,
         1,  1,  3,  1,  4,  1,  1,  1,  1,  1,  2,  1,  1,  1,  2,  1,  2,
         4,  1,  1,  1,  1,  1,  1,  1,  1,  2,  1,  4,  1,  1,  1,  1,  1,
         1,  1,  1,  1,  1,  1,  2,  1,  1,  1,  1,  2,  3,  1,  1,  1,  1,
         1,  1,  1,  1,  1,  1,  1,  1,  1,  3,  1,  1,  1,  1,  3,  4,  2,
         1,  3,  3,  2,  1,  1,  2,  2, 11,  2], dtype=int64))

地图

Map

In [12]:
[list(z) for z in zip(Faker.provinces, Faker.values())]
Out[12]:
[['广东', 76],
 ['北京', 132],
 ['上海', 122],
 ['江西', 51],
 ['湖南', 26],
 ['浙江', 65],
 ['江苏', 69]]
In [13]:
s =[['广东', 28],
 ['北京', 64],
 ['上海', 85],
 ['江西', 65],
 ['湖南省', 139],
 ['湖南', 139],
 ['浙江', 121],
 ['江苏', 115]]
s
Out[13]:
[['广东', 28],
 ['北京', 64],
 ['上海', 85],
 ['江西', 65],
 ['湖南省', 139],
 ['湖南', 139],
 ['浙江', 121],
 ['江苏', 115]]
In [14]:
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker

c = (
Map()
.add("商家A", s, "china") # [['北京',29],['上海',42]]
.set_global_opts(title_opts=opts.TitleOpts(title="Map-基本示例"))

)
c.render_notebook()

Out[14]:
    <div id="d7fd725431fd4a6dbf85fb248098f5c1" style="width:900px; height:500px;"></div>

Geo

In [15]:
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.faker import Faker

c = (
Geo()
.add_schema(maptype="china")
.add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())])
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(), title_opts=opts.TitleOpts(title="Geo-基本示例")
)
)
c.render_notebook()

Out[15]:
    <div id="341b459547ad444c844939a7d4d79ce0" style="width:900px; height:500px;"></div>
In [16]:
import math

from pyecharts.faker import Faker
from pyecharts import options as opts
from pyecharts.charts import Line3D

data = []
for t in range(0, 25000):
_t = t / 1000
x = (1 + 0.25 math.cos(75 _t)) math.cos(_t)
y = (1 + 0.25
math.cos(75 _t)) math.sin(t)
z = t + 2.0 math.sin(75 t)
data.append([x, y, z])
c = (
Line3D()
.add(
"",
data,
xaxis3d_opts=opts.Axis3DOpts(Faker.clock, type
="value"),
yaxis3d_opts=opts.Axis3DOpts(Faker.week_en, type
="value"),
grid3d_opts=opts.Grid3DOpts(width=100, height=100, depth=100),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
max
=30, min_=0, range_color=Faker.visual_color
),
title_opts=opts.TitleOpts(title="Line3D-基本示例"),
)
)
c.render_notebook()

Out[16]:
    <div id="b47de8171c384a3aba5bc3154c235688" style="width:900px; height:500px;"></div>
In [17]:
import pyecharts.options as opts
from pyecharts.charts import Bar3D

"""
Gallery 使用 pyecharts 1.1.0
参考地址: https://echarts.baidu.com/examples/editor.html?c=bar3d-punch-card&gl=1

目前无法实现的功能:

1、光照和阴影暂时无法设置
"""

hours = [
"12a",
"1a",
"2a",
"3a",
"4a",
"5a",
"6a",
"7a",
"8a",
"9a",
"10a",
"11a",
"12p",
"1p",
"2p",
"3p",
"4p",
"5p",
"6p",
"7p",
"8p",
"9p",
"10p",
"11p",
]
days = ["Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday"]

data = [
[0, 0, 5],
[0, 1, 1],
[0, 2, 0],
[0, 3, 0],
[0, 4, 0],
[0, 5, 0],
[0, 6, 0],
[0, 7, 0],
[0, 8, 0],
[0, 9, 0],
[0, 10, 0],
[0, 11, 2],
[0, 12, 4],
[0, 13, 1],
[0, 14, 1],
[0, 15, 3],
[0, 16, 4],
[0, 17, 6],
[0, 18, 4],
[0, 19, 4],
[0, 20, 3],
[0, 21, 3],
[0, 22, 2],
[0, 23, 5],
[1, 0, 7],
[1, 1, 0],
[1, 2, 0],
[1, 3, 0],
[1, 4, 0],
[1, 5, 0],
[1, 6, 0],
[1, 7, 0],
[1, 8, 0],
[1, 9, 0],
[1, 10, 5],
[1, 11, 2],
[1, 12, 2],
[1, 13, 6],
[1, 14, 9],
[1, 15, 11],
[1, 16, 6],
[1, 17, 7],
[1, 18, 8],
[1, 19, 12],
[1, 20, 5],
[1, 21, 5],
[1, 22, 7],
[1, 23, 2],
[2, 0, 1],
[2, 1, 1],
[2, 2, 0],
[2, 3, 0],
[2, 4, 0],
[2, 5, 0],
[2, 6, 0],
[2, 7, 0],
[2, 8, 0],
[2, 9, 0],
[2, 10, 3],
[2, 11, 2],
[2, 12, 1],
[2, 13, 9],
[2, 14, 8],
[2, 15, 10],
[2, 16, 6],
[2, 17, 5],
[2, 18, 5],
[2, 19, 5],
[2, 20, 7],
[2, 21, 4],
[2, 22, 2],
[2, 23, 4],
[3, 0, 7],
[3, 1, 3],
[3, 2, 0],
[3, 3, 0],
[3, 4, 0],
[3, 5, 0],
[3, 6, 0],
[3, 7, 0],
[3, 8, 1],
[3, 9, 0],
[3, 10, 5],
[3, 11, 4],
[3, 12, 7],
[3, 13, 14],
[3, 14, 13],
[3, 15, 12],
[3, 16, 9],
[3, 17, 5],
[3, 18, 5],
[3, 19, 10],
[3, 20, 6],
[3, 21, 4],
[3, 22, 4],
[3, 23, 1],
[4, 0, 1],
[4, 1, 3],
[4, 2, 0],
[4, 3, 0],
[4, 4, 0],
[4, 5, 1],
[4, 6, 0],
[4, 7, 0],
[4, 8, 0],
[4, 9, 2],
[4, 10, 4],
[4, 11, 4],
[4, 12, 2],
[4, 13, 4],
[4, 14, 4],
[4, 15, 14],
[4, 16, 12],
[4, 17, 1],
[4, 18, 8],
[4, 19, 5],
[4, 20, 3],
[4, 21, 7],
[4, 22, 3],
[4, 23, 0],
[5, 0, 2],
[5, 1, 1],
[5, 2, 0],
[5, 3, 3],
[5, 4, 0],
[5, 5, 0],
[5, 6, 0],
[5, 7, 0],
[5, 8, 2],
[5, 9, 0],
[5, 10, 4],
[5, 11, 1],
[5, 12, 5],
[5, 13, 10],
[5, 14, 5],
[5, 15, 7],
[5, 16, 11],
[5, 17, 6],
[5, 18, 0],
[5, 19, 5],
[5, 20, 3],
[5, 21, 4],
[5, 22, 2],
[5, 23, 0],
[6, 0, 1],
[6, 1, 0],
[6, 2, 0],
[6, 3, 0],
[6, 4, 0],
[6, 5, 0],
[6, 6, 0],
[6, 7, 0],
[6, 8, 0],
[6, 9, 0],
[6, 10, 1],
[6, 11, 0],
[6, 12, 2],
[6, 13, 1],
[6, 14, 3],
[6, 15, 4],
[6, 16, 0],
[6, 17, 0],
[6, 18, 0],
[6, 19, 0],
[6, 20, 1],
[6, 21, 2],
[6, 22, 2],
[6, 23, 6],
]
data = [[d[1], d[0], d[2]] for d in data]

(
Bar3D(init_opts=opts.InitOpts(width="1600px", height="800px"))
.add(
series_name="",
data=data,
xaxis3d_opts=opts.Axis3DOpts(type_="category", data=hours),
yaxis3d_opts=opts.Axis3DOpts(type_="category", data=days),
zaxis3d_opts=opts.Axis3DOpts(type_="value"),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
max_=20,
range_color=[
"#313695",
"#4575b4",
"#74add1",
"#abd9e9",
"#e0f3f8",
"#ffffbf",
"#fee090",
"#fdae61",
"#f46d43",
"#d73027",
"#a50026",
],
)
)
.render_notebook()
)

Out[17]:
    <div id="7ef31a2afc1e4234950f6d7eb707fd36" style="width:1600px; height:800px;"></div>

布局

In [18]:
from pyecharts import options as opts
from pyecharts.charts import Bar, Line
from pyecharts.faker import Faker

v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]

bar = (
Bar()
.add_xaxis(Faker.months)
.add_yaxis("蒸发量", v1)
.add_yaxis("降水量", v2)
.extend_axis(
yaxis=opts.AxisOpts(
axislabel_opts=opts.LabelOpts(formatter="{value} °C"), interval=5
)
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="Overlap-bar+line"),
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} ml")),
)
)

line = Line().add_xaxis(Faker.months).add_yaxis("平均温度", v3, yaxis_index=1)
bar.overlap(line)
bar.render_notebook()

Out[18]:
    <div id="733509ba586a407a8fbe111cf4f866c4" style="width:900px; height:500px;"></div>

并行多图Grid

In [19]:
from pyecharts import options as opts
from pyecharts.charts import Bar, Geo, Grid
from pyecharts.faker import Faker

bar = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(legend_opts=opts.LegendOpts(pos_left="20%"))
)

geo = (
Geo()
.add_schema(maptype="china")
.add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())])
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(),
title_opts=opts.TitleOpts(title="Grid-Geo-Bar"),
)
)
grid = (
Grid(init_opts=opts.InitOpts(width="900px",height="900px"))
.add(bar,grid_opts=opts.GridOpts(pos_left="10%",pos_top="80%",is_show=True))
.add(geo,grid_opts=opts.GridOpts(pos_left="90%",pos_top="5%"))
# .add(bar,grid_opts=opts.GridOpts(pos_left="10%",pos_top="80%"))
)

In [20]:
grid.render_notebook()
Out[20]:
    <div id="28ac209da1c64f84b7bd9c335366671f" style="width:900px; height:900px;"></div>

顺序多图

In [21]:
from pyecharts import options as opts
from pyecharts.charts import Bar, Geo, Page
from pyecharts.faker import Faker

bar = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(legend_opts=opts.LegendOpts(pos_left="20%"))
)

geo = (
Geo()
.add_schema(maptype="china")
.add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())])
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(),
title_opts=opts.TitleOpts(title="Grid-Geo-Bar"),
)
)
page = (
Page()
.add(bar)
.add(geo)
)

In [22]:
page.render_notebook()
Out[22]:
    <div id="8f0ae1df01674059960ff01418dcc996" style="width:900px; height:500px;"></div>
    <div id="c85312f74dfa4d94afbd89a28e29822c" style="width:900px; height:500px;"></div>

选项卡

In [23]:
from pyecharts import options as opts
from pyecharts.charts import Bar, Geo, Tab
from pyecharts.faker import Faker

bar = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(legend_opts=opts.LegendOpts(pos_left="20%"))
)
geo = (
Geo()
.add_schema(maptype="china")
.add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())])
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(),
title_opts=opts.TitleOpts(title="Grid-Geo-Bar"),
)
)
tab = (
Tab()
.add(geo,"地图")
.add(bar,"柱形图")
)

In [24]:
tab.render_notebook()
Out[24]:
<style>
    .tab {
        overflow: hidden;
        border: 1px solid #ccc;
        background-color: #f1f1f1;
    }

    .tab button {
        background-color: inherit;
        float: left;
        border: none;
        outline: none;
        cursor: pointer;
        padding: 12px 16px;
        transition: 0.3s;
    }

    .tab button:hover {
        background-color: #ddd;
    }

    .tab button.active {
        background-color: #ccc;
    }

    .chart-container {
        display: none;
        padding: 6px 12px;
        border-top: none;
    }
</style>
    <div id="93b4d6c996ab4704913b7e52ac769319" class="chart-container" style="width:900px; height:500px;"></div>
    <div id="ac903d3913734b549de65143a520681a" class="chart-container" style="width:900px; height:500px;"></div>

时间线轮播

In [25]:
from pyecharts import options as opts
from pyecharts.charts import Pie, Timeline
from pyecharts.faker import Faker

attr = Faker.choose()
t1 = Timeline()
for i in range(2015,2021):
pie = (
Pie()
.add(
"商家A",
[list(z) for z in zip(attr,Faker.values())],
# rosetype="area",
# radius=["30%","55%"],
)
.set_global_opts(title_opts=opts.TitleOpts('某商店{}年营业额'.format(i)))
)
t1.add(pie,"{}年".format(i))
t1.render_notebook()

Out[25]:
    <div id="e836dee330f94025a10c3d0cb18b6cfc" style="width:900px; height:500px;"></div>